<template>
    <div class="home">

        <div class="content-box" style="padding-bottom: 1.3rem">
            <div class="padding-lr-32">

                <ul class="normal-list" v-if="id === 'specialDelay'"> <!--安全 延期 办理-->
                    <li v-for="(item,index) in list" :key="index" @click="select(index)"
                        :class="{active:selected === index}">
                        <!--<li v-for="(item,index) in 6" :key="index" @click="select(index)" :class="{active:selected === index}">-->
                        <h3 class="title3  margin-bottom-10">{{item.specialTypeName}}</h3>
                        <div class="flex justify-between">
                            <div class="normal-list-item" style="width: 60%">
                                <p class="normal-list-item-label margin-bottom-10">证书编号</p>
                                <p class="normal-list-item-val ">{{item.specialNo}}</p>
                            </div>
                            <div class="normal-list-item" style="width: 40%">
                                <p class="normal-list-item-label margin-bottom-10">有效期</p>
                                <p class="normal-list-item-val">{{item.specialEdate}}</p>
                            </div>
                        </div>
                    </li>
                </ul>

                <div class="no-data" v-if="list.length===0">
                    <p>暂无此类证书</p>
                </div>

            </div>
        </div>

        <div class="footer-button">
            <div class="buttonSubmit" v-if="list.length!==0" :class="{disabled:selected===null}" @click="routerTo">
                <span>提交</span>
            </div>
        </div>
    </div>


</template>

<script>
  /* eslint-disable */
    import {Indicator} from 'mint-ui';

    export default {
        name: 'Home',
        data() {
            return {
                id: '',
                selected: null,
                Path: '/detail-reg',
                papersnumber: '',
                list: new Array()
            }
        },
        beforeRouteEnter(to, from, next) {
            let pages = [
                'upFile'
            ];
            if (pages.includes(from.name)) {
                to.meta.isBack = true;
            }
            next();
        },

        activated() {
            if (!this.$route.meta.isBack) {
                this.loadData()
            }
            this.$route.meta.isBack = false

        },
        mounted() {
            this.loadData()
        },
        methods: {

            loadData() {
                let {papersnumber, id, type} = this.$route.query;
                this.id = id || '';
                this.papersnumber = papersnumber;
                console.log(id);
                Indicator.open('加载中...');
                if(this.id === 'specialDelay'){
                    this.GetListSpecial();
                }
            },

            select(data) {
                if (this.selected === data) {
                    this.selected = null
                } else {
                    this.selected = data
                }

            },

            routerTo() {
                //todo弹出对话框，提交数据
              let _this = this;
              if(this.selected!=null){
                let certNo=this.list[this.selected].specialNo;
                console.log(certNo)
                this.$bridge(function () {
                  AlipayJSBridge.call('confirm', {
                    message: '确定延长此证书？',
                    align:'center',
                    okButton: '确定',
                    cancelButton: '取消'
                  },function (e) {
                    if(e.ok){
                      _this.submitApply(certNo)
                    }
                  });
                });
              }else {
                  console.log("请选择证书")
              }

            },

            submitApply(certNo){
              let _this = this;
                Indicator.open('正在提交...');
                let date = new Date().getTime().toString();
                let sign = this.$md5('SAFETYYQSQ' + date);
                let param = {
                    from: '3',
                    key: '3d9865e0e0b14ca784127d68e9c160b0',
                    sign: sign,
                    requestTime: date,
                    cardNo:this.papersnumber,
                    certNo:certNo,
                    certType:'RY_SPECIAL',
                    applyType:'RY_YWSQLB_YX'
                   // ryCard: this.papersnumber
                };
                this.$api.post('/jimp/link.do', {param: JSON.stringify(param)}, response => {

                    if (response.status === 200 && (response.data.result || response.data.code === "200")) {
                      Indicator.close();
                      this.$bridge(function () {
                        AlipayJSBridge.call('toast', {
                          content: '提交成功',type: 'success',duration: 1500
                        },function () {
                          _this.$router.go(-1);
                        })
                      })

                    }else {
                      Indicator.close();
                      this.$bridge(function () {
                        AlipayJSBridge.call('toast', {
                          content: response.data.msg?response.data.msg:'提交失败',type: 'fail',duration: 1500
                        },function () {
                          _this.$router.go(-1);
                        })
                      })

                    }

                });
            },
            GetListSpecial: function (data) {  //特种证书查询
                let date = new Date().getTime().toString();
                let sign = this.$md5('rySpecial' + date);
                let param = {
                    from: '3',
                    key: '534d996466b741b9827404104f2ccfcd',
                    sign: sign,
                    requestTime: date,
                    // ryCard:'362531198810042416',
                     ryCard: this.papersnumber
                };
                this.$api.post('/jimp/link.do', {
                    param: JSON.stringify(param)
                }, response => {
                    console.log(response);
                    if (response.status === 200 && (response.data.result || response.data.code === "200")) {
                        this.list = response.data.data;
                    } else {
                        this.list = [];
                    }
                    Indicator.close();
                });
            },
        }
    }
</script>


<style lang="less" scoped>
    .normal-list {
        li {
            border: 1px solid transparent;
            &.active {
                border: 1px solid #2b92fc;
                background: url("../../assets/images/right.png") no-repeat top 0.1rem right 0.1rem;
                background-size: 0.4rem;
            }
        }
    }
</style>
